<?php
/** 
 * A XML parser exception
 * 
 * This class is a exception for XMLParser
 * 
 * @author Thuan Chau <thuanchau2020@gmail.com>
 * @package XMLParserException
 */
class XMLParserException extends Exception {
	/**
	 * @const int error code if can not open file
	 */
	const CODE_CAN_NOT_OPEN_FILE				= 10001;
	/**
	 * @const string error message if can not open file
	 */
	const MESSAGE_CAN_NOT_OPEN_FILE				= "Could not open XML file";

	/**
	 * Construct the exception
	 * 
	 * @param string $message [optional]
	 * @param int $code [optional]
	 * @access public
	 */
	public function __construct($message = NULL, $code = 0) {
		parent::__construct($message, $code);
	}

	/**
	 * This try to get exception from a XML parser resource
	 * 
	 * @param resource $xml_parser a XML parser resource
	 * @return XMLParserException return a XMLParserException if has error in XML parser
	 * resource, or else return NULL.
	 * @access public
	 * #static
	 */
	public static function tryGetException($xml_parser) {
		$code = xml_get_error_code($xml_parser);
		$message = xml_error_string($code);

		return (empty($code) ? NULL : new XMLParserException($message, $code));
	}
}
?>